<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<%@include file="/common/javascript.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>求教</title>
    <link href="${ctx}/static/css/index.css" rel="stylesheet" type="text/css" /> 
    <link href="${ctx}/static/ligerui/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" /> 
    <link href="${ctx}/static/ligerui/lib/css/common.css" rel="stylesheet" type="text/css" />  
    <link href="${ctx}/static/ligerui/lib/css/index.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

var dialog;

var myQuestionGrid;
var orderListGrid;
var currentQuestionGrid;
//加载正在处理中的问题
function loadCurrentQuestion(options){
	var o= options || {url:"${ctx}/qso/helpque/processing" };
	currentQuestionGrid.setOptions(o);
	currentQuestionGrid.loadData(false);//设置false,否则会再次发起请求
	
}
//加载我当前课程提的所有问题
function loadMyQuestion(options){
	var o= options || {url:"${ctx}/qso/helpque/myQuestion",parms: [{ name: "search_EQ_hpqStatus", value:"WT" },{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}]};
	myQuestionGrid.setOptions(o);
   	myQuestionGrid.loadData(false);//设置false,否则会再次发起请求
}
//加载排队情况
function loadOrderList(){
	var o={url:"${ctx}/qso/helpque/orderList",parms: [{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}]};
	orderListGrid.setOptions(o);
	orderListGrid.loadData(false);//设置false,否则会再次发起请求
/*  	LG.ajax({
		url:"${ctx}/qso/helpque/orderList",
		success:function(result){
			orderListGrid.set({ data: result}); 
		}
	});  */ 
}

//提问之后回调
function askQuestionSuccess(){
	dialog.close();
	loadMyQuestion();
}

//点击 状态过滤
function checkMyQuestion(checkObj){
	$("#myQuestionToolbar").find("input[name='checkMyQuestion']").each(
			function(index) {
				$(this).attr("checked", false);
	});
	
	if(checkObj.value=="WT"){
		$("#undoButton").show();
	}else{
		$("#undoButton").hide();
	}
	checkObj.checked=true;

    var options={
    		parms: [{ name: 'search_EQ_hpqStatus', value:checkObj.value },{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}],
    		url:"${ctx}/qso/helpque/myQuestion"
    };
    loadMyQuestion(options);

}

//撤销
function undoQuestion(){
    var data = myQuestionGrid.getCheckedRows();
    if (data.length == 0)
    	LG.tip('请选择行!');
    else
    {
        var checkedIds = [];
        $(data).each(function ()
        {
            checkedIds.push(this.hpqId);
        });
        $.ligerDialog.confirm('确定撤销 吗?', function (flag)
        {
        	if(flag){
                LG.ajax({
                	url:"${ctx}/qso/helpque/undoQuestion",
                    loading: '正在撤销中...',
                    data:{ids:checkedIds.join(',')},
                    success: function (result) {
                        LG.showSuccess(result.message);
                        loadMyQuestion();
                    },
                    error: function (result) {
                        LG.showError(result.message);
                    }
                });
        	}

        }); 
    }
}

function askQuestion()
{
	dialog=$.ligerDialog.open({url: '${ctx}/qso/helpque/view/add?hpqId=',height:350, width:650, showMax: false, showToggle: false, showMin: true, isResize: false, modal: true, title:"提问"});
}

$(function (){
	$("#mainbody").ligerLayout({ height: '100%', heightDiff: -3, leftWidth: 140,minLeftWidth: 120 });
	var bodyHeight = $(".l-layout-center:first").height();
    //tab = $("#framecenter").ligerTab({ height: bodyHeight, contextmenu: true });
	var tab=$("#framecenter").ligerTab({ 
		height: bodyHeight,
		onAfterSelectTabItem: function (tabid)
        {
        	if(tabid=="myQuestion"){
        		loadMyQuestion();
        	}else if(tabid=="orderList"){
        		loadOrderList();
        	}else if(tabid=="currentQuestion"){
        		loadCurrentQuestion();
        	}
    	}  
	}); 
	
    //预加载dialog的背景图片
    LG.prevDialogImage("${ctx}");

    $("#pageloading").hide();

    //正在解决的问题
    currentQuestionGrid = $("#currentQuestionGrid").ligerGrid({
        columns: [
        { display: '问题', name: 'hpqQuestion',width: 390, minWidth: 120},
        { display: '学生', name: 'stuName',width: 170, minWidth: 120},
       	{ display: '老师', name: 'teaName',width: 170, minWidth: 120},
        {
            display: '操作', isAllowHide: false,width:170,minWidth:120,
            render: function (row)
            {
                return '<a href="javascript:void(0);" onclick="joinGroup(\'' + row.groupId + '\')">加入</a>';
            }
        },
        {name : 'groupId',hide: true,width:1}
        ], width: '100%', pkName: 'hpqId',height: '100%',checkbox : false,usePager:false
        
    });
    
    //我的提问
    myQuestionGrid = $("#myQuestionGrid").ligerGrid({
        columns: [
        {display: '问题', isAllowHide: false,width:430,minWidth:120,
       	render: function (row)
             {
       			if(row.status == 'CO'){
       			 	return '<a href="javascript:void(0);" onclick="toDetail(\'' + row.groupId + '\')">'+row.hpqQuestion+'</a>';
       			}else{
       				return row.hpqQuestion;
       			}
             }
        },
        { display: '时间', name: 'dateCre',width: 220, minWidth: 120},
        { display: '状态', name: 'hpqStatus',width: 220, minWidth: 120}
        ], width: '100%', pkName: 'hpqId',height: '100%',checkbox : true,usePager:false,
        parms : [{name : 'search_EQ_hpqStatus',value : 'WT'}]
        
    });
    
    //排队情况
    orderListGrid = $("#orderListGrid").ligerGrid({
        columns: [
        { display: '问题', name: 'hpqQuestion',width: 370, minWidth: 120},
        { display: '时间', name: 'dateCre',width: 170, minWidth: 120},
        { display: '状态', name: 'hpqStatus',width: 170, minWidth: 120},
        { display: '提问人', name: 'stuName',width: 170, minWidth: 120}
        ], width: '100%', pkName: 'hpqId',height: '100%',usePager:false
        
    });
   
    //初始化我的问题
	tab.selectTabItem("myQuestion");
    
    //初始化正在处理中的问题
    //loadCurrentQuestion();
    
    $("[tabid='currentQuestion']").find('a:first').prepend('<img src="../../static/css/student/img/help-icon-01.png" /> ');
    $("[tabid='myQuestion']").find('a:first').prepend('<img src="../../static/css/student/img/help-icon-02.png" /> ');
    $("[tabid='orderList']").find('a:first').prepend('<img src="../../static/css/student/img/help-icon-03.png" /> ');
    
    $(".l-panel").css("width", "98%");
        
});

function joinGroup(groupId){
	window.parent.initiativeJoin(groupId);
}

function toDetail(groupId){
	var geo=getWinGeometry(window);
	dialog=$.ligerDialog.open({url: '${ctx}/qso/instruct/toDetail/'+groupId,height:geo.height,width:geo.width, showMax: true, showToggle: true, showMin: true,isResize:false,isDrag:false,modal: true, title:"详细"});
}
</script>   
</head>
<body style="text-align:center; background:url('${ctx}/static/ligerui/lib/images/qso/bg-1477x768.jpg'); overflow:hidden;">
    <div id="pageloading" style="display:block;"></div> 
    <div id="topmenu" class="l-topmenu" style="height:40px;">
        <div class="l-topmenu-logo" style="padding-left: 15px; padding-top:10px"><img src="${ctx}/static/css/student/img/help-title-1.png" /></div>      
    </div> 
     <div id="mainbody" class="l-mainbody" style="width:99.2%; margin:0 auto; margin-top:3px;" >
        <div position="center" id="framecenter" style="background:#FFFFFF;">
			<div title="当前问题" lselected="true" style="height:100%;" tabid="currentQuestion" id="test1">
			    <div style=" width:100%" id="mainsearch">
    				<div class="searchbox" style="padding:10px 10px 0 10px;">
        				<div class="l-clear"></div>
    				</div>
			    </div>
				<div id="currentQuestionGrid" style="margin:1px; height:100%; width:98%;">	
				</div>		
			</div>
			
			<div title="我的问题" tabid="myQuestion" id="myQuestionToolbar">
			   <div style=" width:100%" id="mainsearch">
   					<div class="searchbox" style="padding:10px 10px 0 10px;">
        					<div style="float:left;color:#444;padding-top:5px;">状态:</div>
        					<div style="float:left; margin-left:15px;padding-top:5px;">
        						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="WT" checked="checked" style="vertical-align:middle;"/>
        						<span>等待</span>
        					</div>
        					<div style="float:left; margin-left:10px;padding-top:5px;">
        						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="CO" style="vertical-align:middle;"/> 
        						<span>完成</span>
        					</div>
        					<div style="float:left; margin-left:10px;padding-top:5px;">
        						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="DL" style="vertical-align:middle;"/> 
        						<span>拒绝</span>
        					</div>
        					<div class="inst-chat-send" style="float:right;margin-right:20px;">
				            	<div style="width:80px" class="button button2" onclick="askQuestion()">
									<div class="button-l"> </div>
									<div class="button-r"> </div> 
									<div class="button-icon"><img src="${ctx}/static/css/student/img/help-icon-05.png" style="vertical-align:middle;" /> </div>
									<span>我要提问</span>
								</div>
				            </div>
							<div class="inst-chat-send" style="float:right;margin-right:10px;" id="undoButton">
				            	<div style="width:60px;" class="button button2" onclick="undoQuestion()">
									<div class="button-l"> </div>
									<div class="button-r"> </div> 
									<div class="button-icon"><img src="${ctx}/static/css/student/img/help-icon-06.png" style="vertical-align:middle;" /> </div>
									<span>撤销</span>
								</div>
				            </div>				            
				            
        					<div class="l-clear"></div>
    				</div>
				</div>
				<div id="myQuestionGrid" style="margin:1px; height:100%; width:98%;">
					
				</div>
			</div>
			
			<div title="排队情况" tabid="orderList">
			 	<div style=" width:100%" id="mainsearch">
    				<div class="searchbox" style="padding:10px 10px 0 10px;">
        				<div class="l-clear"></div>
    				</div>
			    </div>
				<div id="orderListGrid" style="margin:1px; height:100%; width:98%;">
					
				</div>
			</div>	
				
		</div>
    </div>    
</body>
</html>